import Vue from 'vue'
import App from './App.vue'
import router from './router/index'//路由
import store from './store/index' // vuex
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 引入初始化css文件
import './index.css'

Vue.config.productionTip = false

Vue.use(router)
Vue.use(ElementUI)

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  if (token) {
    next()
  } else {
    if (to.path === "/index") {
      next('/')
    } else {
      next()
    }
  }

});

// window.addEventListener('beforeunload', function () {
//   this.localStorage.removeItem('token')
// });



new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
